package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理模块")
public class DishController {
    @Autowired
    private DishService dishService;

    @ApiOperation("菜品分页查询")
    @GetMapping("/page")
    public Result selectAllDish(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult = dishService.selectAllDish(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("新增菜品")
    @PostMapping
    public Result insertDish(@RequestBody DishDTO dishDTO){
        dishService.insertDish(dishDTO);
        return Result.success();
    }

    @ApiOperation("批量删除")
    @DeleteMapping
    public Result deletesDish(@RequestParam List<Integer> ids){
        dishService.deltesDish(ids);
        return Result.success();
    }

    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public Result<DishVO> getById(@PathVariable Long id){
        return Result.success(dishService.getById(id));
    }

    @ApiOperation("修改")
    @PutMapping
    public Result updateById(@RequestBody DishVO dishVO){
        dishService.updateById(dishVO);
        return Result.success();
    }

    @ApiOperation("菜品起售停售")
    @PostMapping("status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id){
        dishService.updateStatusById(status,id);
        return Result.success();
    }

    @ApiOperation("根据分类id查询菜品")
    @GetMapping("/list")
    public Result selectDishByCategoryId(Long categoryId){
        List<DishVO> list = dishService.selectDishByCategoryId(categoryId);
        return Result.success(list);
    }
}